var ReplyModel=require('../models/reply')
var path=require('path')
var fs=require('fs')
exports.addReply=(req,res)=>{
	var topicId=req.body.topicId
	var content=req.body.t_content
	var data={
		topicId:topicId,
		content:content,
		username:global.current_user.username,
		insertTime:Date.now()
	}
	ReplyModel.addReply(data,()=>{
		res.redirect('/topic/'+topicId)
	})
}
exports.upload=(req,res)=>{
	req.pipe(req.busboy)
	req.busboy.on('file',(fieldname,file,filename,mimetype)=>{
		var newfilename=String(Date.now())+path.extname(filename);
		var filePath=__dirname+'/../public/upload/'+newfilename
		file.pipe(fs.createWriteStream(filePath))
		file.on('end',()=>{
			return res.json({success:true,url:'/upload/'+newfilename})
		})
	})
}